<template>
  <div>
    <el-button @click="getEditVal">取值</el-button>
    <yu-ace-editor :data="editorStr" lang="json" v-model:value="editorStr" @handleCells="handleCells" @handleFormat="handleFormat"></yu-ace-editor>
    <div style="padding: 8px 0">
      <el-button type="primary" @click="handleCells">压缩</el-button>
      <el-button type="primary" @click="handleFormat">格式化</el-button>
    </div>
    <div>sql</div>
    <yu-ace-editor :data="data.sql" lang="sql" v-model:value="data.sql"></yu-ace-editor>
  </div>
</template>
<script setup>
  import { reactive, ref, toRefs, onMounted, getCurrentInstance } from 'vue';

  const readonly = ref(false);
  const theme = ref('solarized_light');
  const getEditVal = () => {
    alert(editorStr.value);
  };
  const data = reactive({
    sql: '',
  });
  data.sql = "SELECT * from sys_user where user_name = 'test'";

  const editorStr = ref(
    JSON.stringify(
      {
        title: '测试json数据233',
        child: [
          {
            title: '子项名称1',
            desc: '子项描述1',
          },
          {
            title: '子项名称2',
            desc: '子项描述2',
          },
        ],
      },
      null,
      2
    )
  );
  const handleCells = () => {
    editorStr.value = JSON.stringify(JSON.parse(editorStr.value), null, 0);
  };
  // 压缩
  const handleZip = () => {
    jsonStr.value = JSON.stringify(JSON.parse(jsonStr.value), null, 0);
  };
  //格式化
  const handleFormat = () => {
    editorStr.value = JSON.stringify(JSON.parse(editorStr.value), null, 2);
  };
</script>
